package com.attendcollatesys;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SplitStrings {
    public static void main(String[] args) {
        //String s = "ABCDG";
        //System.out.println(Arrays.toString(t("ABCDGpolpos")));

        System.out.println(summaryRanges(new int[]{0, 2, 3, 4, 6, 8, 9}));

    }


    public static List<String> summaryRanges(int[] nums) {
        int length = nums.length;
        ArrayList<String> result = new ArrayList<>();
        StringBuilder res = new StringBuilder();
        for (int left= 0; left < length; ) {
            res.setLength(0);
            res.append(nums[left]);
            while (true) {
                if(left+1<length&&nums[left]+1==nums[left+1]){
                    left++;
                }
                    if(!(res.toString().equals(Integer.toString(nums[left])))){
                        res.append("->").append(nums[left]);
                    }
                    result.add(res.toString());
                    left++;
                    break;

            }
        }

        return result;



    }

    public static String[] t(String s) {

        int length = s.length();
        String[] result;

        if (length % 2 == 0) {
            result = new String[length / 2];
        } else {
            result = new String[length / 2 + 1];
            s += "_";
        }
        int index = 0;
        for (int i = 0; i < s.length(); i += 2) {
            String substring = s.substring(i, i + 2);
            result[index] = substring;
            index++;
        }

        return result;
    }

    @Test
    public void test12(){
        System.out.println("h");
    }


}
